<template>
  <div class="app-container">
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="IP地址" prop="ip" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.ip }}</span>
        </template>
      </el-table-column>
      <el-table-column label="系统信息" prop="agent">
        <template slot-scope="scope">
          <span>{{ scope.row.agent }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户地址" prop="address" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="浏览器信息" prop="browser" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.browser }}</span>
        </template>
      </el-table-column>
      <el-table-column label="浏览器版本" prop="browserVersion" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.browserVersion }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备操作系统" prop="os" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.os }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作系统的版本号" prop="osVersion" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.osVersion }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button size="mini" type="danger" @click="handleDelete(row)">
            <i class="fa fa-trash-o fa-lg"/>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>
import { feachList, del } from '@/api/logs'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
export default {
  name: 'Logs',
  components: {
    Pagination
  },
  data() {
    return {
      listLoading: false,
      tableKey: 0,
      total: 0,
      list: [],
      listQuery: {
        page: 1,
        limit: 10
      },
      dialogStatus: '',
      dialogFormVisible: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      const { result } = await feachList(this.listQuery)
      this.listLoading = false
      this.list = result.list
      this.total = result.total
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    message(title, type, message) {
      this.$notify({
        title: title,
        message: message,
        type: type,
        duration: 2000
      })
    },
    handleDelete(row) {
      MessageBox.confirm(`是否确认删除【${row.name}】这条数据？`, '删除', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(row.id).then(res => {
          if (res.code === 0) {
            this.message('删除标签', 'success', res.message)
            this.dialogFormVisible = false
            this.handleFilter()
            this.$store.dispatch('tag/getTagList')
          }
        })
      })
    }
  }
}
</script>
